<?php

namespace Houdunren\WeChat\Button;

use hisorange\BrowserDetect\Exceptions\Exception;
use Houdunren\WeChat\WeChat;
use Illuminate\Support\Facades\Http;

trait CreateButton
{

    public function create(array $button)
    {

        //token在基类中，功能列添加至扩展类，可以使用基类的方法
        $url = $this->api . '/menu/create?access_token=' . $this->token();
//不解析不是unicode的编码。以比肩中文json导致微信服务器无法解析
        $response = Http::send('POST', $url, ['body' => json_encode($button, JSON_UNESCAPED_UNICODE)])->throw()->json();
        //


        if ($response['errcode'] == 0) {
            return true;
        }
        throw new Exception($response['errmsg']);

    }


}
